package com.css.zfzx.fwsjcj.modules.taskmanage.taskfrom.repository;

import com.css.zfzx.fwsjcj.commen.util.Constant;
import com.css.zfzx.fwsjcj.modules.taskmanage.taskfrom.entity.FwCtiyHouseEntity;
import com.css.zfzx.fwsjcj.modules.taskmanage.taskfrom.entity.FwNoctiyHouseEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NoCityTaskRepository extends JpaRepository<FwNoctiyHouseEntity, String>, JpaSpecificationExecutor<FwNoctiyHouseEntity> {
    @Modifying
    @Query(nativeQuery = true, value = "update fw_noctiy_house set sp_type = :spType where fw_id =:id ")
    void suById(@Param("id") String id, @Param("spType") String spType);

    @Modifying
    @Query(nativeQuery = true, value = "update fw_noctiy_house set is_valid = '" + Constant.IS_VALID_NO + "' where fw_id =:id")
    void deletByFromId(@Param("id") String id);

    @Modifying
    @Query(nativeQuery = true, value = "update fw_noctiy_house set reason =:reason,sp_type =:status where fw_id = :formId")
    void spReason(@Param("status") String status, @Param("reason") String reason, @Param("formId") String formId);

    /**
     * 查询总数
     */
    @Modifying
    @Query(nativeQuery = true, value = "select count(*) from fw_noctiy_house where is_valid =1")
    Long findAllCount();

    /**
     * 查询在idList中数据
     */
    @Query(nativeQuery = true, value = "select * from fw_noctiy_house where is_valid=" + Constant.IS_VALID_YES + " and fw_id in :formIdList")
    List<FwNoctiyHouseEntity> findInIdList(@Param("formIdList")List<String> formIdList);

    @Query(nativeQuery = true, value = "select back_opinion from fw_noctiy_house where is_valid=" + Constant.IS_VALID_YES + " and fw_id = :fwId")
    String findByFwId(@Param("fwId")String fwId);
}
